/*nss_raw
started 8/31/20
paul stainier
*/


clear all
*grayscale
set scheme s2mono

***************************
*replace with own directories
***************************
input = 
local input_10 = 
local varname_input =  
local output = 
local output_10 = 


***************************
*toggle yes/no to decide
*which programs to run
***************************
local clean_vars = "yes"
local clean_vars_sched10 = "yes"


***************************
*
*clean_vars
*clean variable names stata
*
***************************
if "`clean_vars'" == "yes"{
	foreach file_num of numlist 1(1)42{
		cd `input'
		insheet using filenames.csv, clear
		local round_num = round in `file_num'
		local block = block in `file_num'
		local filename = filename in `file_num'
		local type_name = type in `file_num'
		cd `varname_input'
		insheet using round`round_num'block`block'_varnames.csv, clear names
		unab b: _all
		cd `input'/`round_num'
		use "`filename'", replace
		unab a: _all
		rename (`a') (`b')
		cd `output'/`round_num'
		outsheet using  nss_`round_num'_`type_name'.csv, comma replace
	}
}

***************************
*
*clean_vars_sched10
*clean variable names stata
*
***************************
if "`clean_vars_sched10'" == "yes"{
	foreach file_num of numlist 1(1)34{
		cd `input_10'
		insheet using filenames10.csv, clear
		local round_num = round in `file_num'
		local block = block in `file_num'
		local type_name = type in `file_num'
		insheet using varnames/round`round_num'block`block'varnames.csv, clear names
		unab b: _all
		cd `input_10'/`round_num'
		use round`round_num'block`block', replace
		unab a: _all
		rename (`a') (`b')
		cd `output_10'/`round_num'
		outsheet using nss10_round`round_num'_`type_name'.csv, comma replace
	}
}
